//
//  AppForClaLeaUpLoadPhoViewController.m
//  AttendenceSys
//
//  Created by ld on 16/1/23.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "AppForClaLeaUpLoadPhoViewController.h"
#import "FTPhotoAlbumController.h"

@interface AppForClaLeaUpLoadPhoViewController ()

@end

@implementation AppForClaLeaUpLoadPhoViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //[self initView];
    _releaseArrImage = [[NSMutableArray alloc] init];
    [self initNewView];
}

- (void)initNewView
{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    UIImageView* imageHeadView = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-100) / 2,
                                                                               32.5,
                                                                               100,
                                                                               100)];
    [imageHeadView setBackgroundColor:[UIColor clearColor]];
    [imageHeadView setImage:[UIImage imageNamed:@"ic_prove"]];
    [self.view addSubview:imageHeadView];
    
    // separateLine
    UIImageView* separateLineTop = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                              imageHeadView.frame.origin.y + imageHeadView.frame.size.height + 19,
                                                                              width,
                                                                              1)];
    [separateLineTop setBackgroundColor:[UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1.0]];
    [self.view addSubview:separateLineTop];
    
    _actContentTxtView = [[UITextView alloc] initWithFrame:CGRectMake(5,
                                                                      imageHeadView.frame.origin.y + imageHeadView.frame.size.height + 20,
                                                                      width,
                                                                      UpRemarkLoadCellHeight - 10)];
    _actContentTxtView.delegate = self;
    _actContentTxtView.textColor = [UIColor blackColor];
    _actContentTxtView.textAlignment = NSTextAlignmentLeft;
    _actContentTxtView.backgroundColor =  [UIColor clearColor];
    _actContentTxtView.font = [UIFont systemFontOfSize:16.0];
    _actContentTxtView.layer.cornerRadius = 3;
    _actContentTxtView.returnKeyType = UIReturnKeyDone;
    _actContentLab = [[UILabel alloc] initWithFrame:CGRectMake(5, 7, _actContentTxtView.frame.size.width, 20)];
    _actContentLab.enabled = NO; //lable必须设置为不可用
    _actContentLab.backgroundColor = [UIColor clearColor];
    _actContentLab.text = @"申请课时假备注描述";
    _actContentLab.font = [UIFont systemFontOfSize:16.0];
    _actContentLab.textColor = [UIColor colorWithRed:134/255.0 green:139/255.0 blue:142/255.0 alpha:1];
    [_actContentTxtView addSubview:_actContentLab];
    [self.view addSubview:_actContentTxtView];
    
    // separateLine
    UIImageView* separateLineBottom = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                              _actContentTxtView.frame.origin.y + _actContentTxtView.frame.size.height + 1,
                                                                              width,
                                                                              1)];
    [separateLineBottom setBackgroundColor:[UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1.0]];
    [self.view addSubview:separateLineBottom];
    
    [self initScrollView:_releaseArrImage];
    
    // 提交
    _submitBtn = [[UIButton alloc] initWithFrame:CGRectMake(55,
                                                            _imageScrollView.frame.origin.y + _imageScrollView.frame.size.height + 30,
                                                            self.view.frame.size.width - 2 * 55,
                                                            50)];
    [_submitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [_submitBtn addTarget:self action:@selector(submitRequest) forControlEvents:UIControlEventTouchUpInside];
    [_submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _submitBtn.backgroundColor = RGB(253, 119, 62);
    [self.view addSubview:_submitBtn];
}

- (void)initScrollView:(NSMutableArray*)arrImage
{
    if (_imageScrollView)
    {
        [_imageScrollView removeFromSuperview];
    }
    
    _imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
    _imageScrollView.frame = CGRectMake(0,
                                        _actContentTxtView.frame.origin.y + _actContentTxtView.frame.size.height + 50,
                                        [UIScreen mainScreen].bounds.size.width,
                                        70);
    _imageScrollView.directionalLockEnabled = YES; //只能一个方向滑动
    _imageScrollView.pagingEnabled = YES; //是否翻页
    _imageScrollView.backgroundColor = [UIColor clearColor];
    _imageScrollView.showsVerticalScrollIndicator = NO; //垂直方向的滚动指示
    _imageScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
    _imageScrollView.showsHorizontalScrollIndicator = YES;//水平方向的滚动指示
    _imageScrollView.userInteractionEnabled = YES;
    _imageScrollView.delegate = self;
    [self.view addSubview:_imageScrollView];
    
    //设置滚动视图的位置
    [_imageScrollView setContentSize:CGSizeMake(([UIScreen mainScreen].bounds.size.width / 5 * (arrImage.count + 1)),
                                                _imageScrollView.frame.size.height)];
    
    for (unsigned int i = 0; i < arrImage.count; i++)
    {
        NSData* data = [arrImage objectAtIndex:i];
        UIButton* imageBtnView = [[UIButton alloc] initWithFrame:CGRectMake(10 * (i + 1) + i * ([UIScreen mainScreen].bounds.size.width - 60) / 5,
                                                                            0,
                                                                            ([UIScreen mainScreen].bounds.size.width - 60) / 5,
                                                                            ([UIScreen mainScreen].bounds.size.width - 60) / 5)];
        [imageBtnView setBackgroundColor:[UIColor redColor]];
        imageBtnView.contentMode = UIViewContentModeScaleAspectFill;
        //UIViewContentModeScaleAspectFit
        UIImage* image = [UIImage imageWithData:data];
        [imageBtnView setBackgroundImage:image forState:UIControlStateNormal];
        [_imageScrollView addSubview:imageBtnView];
    }
    
    NSInteger count = arrImage.count;
    UIButton* addBtn = [[UIButton alloc] initWithFrame:CGRectMake(10 * (count + 1) + count * ([UIScreen mainScreen].bounds.size.width-60) / 5,
                                                                  0,
                                                                  ([UIScreen mainScreen].bounds.size.width - 60) / 5,
                                                                  ([UIScreen mainScreen].bounds.size.width - 60) / 5)];
    addBtn.backgroundColor = [UIColor clearColor];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"ic_add"] forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addImage) forControlEvents:UIControlEventTouchUpInside];
    [_imageScrollView addSubview:addBtn];
}

- (void)initView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView registerClass:[AppForClaLeaUpLoadPhotoCell class]
       forCellReuseIdentifier:NSStringFromClass([AppForClaLeaUpLoadPhotoCell class])];
    [self.view addSubview:_tableView];
    [self initTabHeadView];
    
    //点击事件
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapped:)];
    tap.delegate = self;
    //tap.cancelsTouchesInView = NO;
    [self.tableView.tableHeaderView addGestureRecognizer:tap];
}

/**
 *	@brief	cell点击事件
 *
 *	@param 	gestureRecognizer 	手势
 */
- (void)cellTapped:(UITapGestureRecognizer *)gestureRecognizer
{
    [_actContentTxtView resignFirstResponder];
    _tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}

- (void)initTabHeadView
{
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 217.5)];
    
    UIImageView* imageHeadView = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-100)/2, 32.5, 100, 100)];
    [imageHeadView setBackgroundColor:[UIColor clearColor]];
    [imageHeadView setImage:[UIImage imageNamed:@"ic_prove"]];
    [view addSubview:imageHeadView];
    
    UILabel* infoLab = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 152.5, 200, 25)];
    [infoLab setBackgroundColor:[UIColor clearColor]];
    infoLab.font = [UIFont systemFontOfSize:17];
    [infoLab setTextAlignment:NSTextAlignmentCenter];
    infoLab.text = @"请上传学院请假申请证明";
    infoLab.textColor = RGB(102, 102, 102);
    [view addSubview:infoLab];
    
    _tableView.tableHeaderView = view;
}

- (void)addImage
{
    FTPhotoAlbumController* phoAlbum = [[FTPhotoAlbumController alloc] init];
    phoAlbum.albumDelegate = self;
    phoAlbum.videoDelegate = self;
    phoAlbum.albumType = AlbumType_MutiForSending;
    ASBaseNavigationController* baseNavi = [[ASBaseNavigationController alloc] initWithRootViewController:phoAlbum];
    [self presentViewController:baseNavi animated:YES completion:nil];
}


#pragma mark - FTAlbumPhotoViewControllerDelegate
/**
 *  确认或发送图片回调
 *
 *  @param info        图片数组
 *  @param isOriginImg 是否是原图
 */
- (void)albumDidFinishPickingWithInfo:(NSMutableArray *)info
                          IsOriginImg:(BOOL)isOriginImg
                        withAlbumType:(AlbumType)albumType
{
    //_arrImage = info;
    //[self uploadImage];
    _releaseArrImage = info;
    [self initScrollView:_releaseArrImage];
    
    NSInteger offsetCount = 0;
    if (4 < _releaseArrImage.count)
    {
        offsetCount = _releaseArrImage.count - 4;
        [_imageScrollView setContentOffset:CGPointMake(10 * offsetCount + offsetCount * ([UIScreen mainScreen].bounds.size.width - 60) / 5, 0)];
    }
}

#pragma mark - RCSVideoPickerDelegate
- (void)selectedVideoDictionary:(NSDictionary *)videoDic
                 pickController:(UIViewController *)ctr
                      videoData:(NSMutableArray*)videoData
{
}

- (void)submitRequest
{
    //外出假接口 http://211.65.216.54/uploadAction.do?type=2&leaveType=3&userCode=xiaohu&leaveDate=2016-02-26,2016-02-27&termId=1 //考勤外出假的时候type=3 写死2 服务端有用 leaveType请假类型(1按天请假2请课假 3外出假) leaveReason请假理由courseId课程主键leaveDate请假日期weekDay星期几courseNumber第几节课startDate开始日期(yyyy-MM-dd)endDate结束日期(yyyy-MM-dd) termId//学期id
    
    NSString* refer = @"uploadAction.do?";
    NSString* prefix = kASHttpUrl(refer);
    NSString* totalUrl;
    if (!_bIsOutLeave)
    {
        /****************** mod 0923
        //[self applyForClass:_strDate courseNumId:_strCourseNum];
        totalUrl = [NSString stringWithFormat:@"%@type=%@&leaveType=%@&leaveReason=%@&userCode=%@&leaveDate=%@&courseNumber=%@&termId=%@",prefix, @"2", @"2", _actContentTxtView.text,AS_APP_UserCode, _strDate, _strCourseNum, @"1"];
         *******************/
        
        // mod 0923 请课时假和couseID不相关
        totalUrl = [NSString stringWithFormat:@"%@type=%@&leaveType=%@&leaveReason=%@&userCode=%@&leaveDate=%@&teacherIds=%@&courseNames=%@&termId=%@",prefix, @"4", @"2", _actContentTxtView.text, AS_APP_UserCode, _strDate, _teacherID, _courseName, @"1"];
    }
    else
    {
        //[self ApplyForOutHoliday:_sSelectDate];
        totalUrl = [NSString stringWithFormat:@"%@type=%@&leaveType=%@&leaveReason=%@&userCode=%@&leaveDate=%@&termId=%@",prefix, @"2", @"3", _actContentTxtView.text, AS_APP_UserCode, _sSelectDate, @"1"];
    }
    
    [SVProgressHUD showWithStatus:@"提交..." maskType:SVProgressHUDMaskTypeClear];
    typeof(self) __weak weakSelf = self;
    
    ASNetworkEngine *networkingEngine = [ASNetworkEngine sharedInstance];
    [networkingEngine uploadImagesWithUrl:totalUrl image:_releaseArrImage progressBlock:^(long long bytesRead, long long totalBytes) {
        
    } completionBlock:^(id responseObject) {
        
        NSDictionary* jsonRsp = (NSDictionary *)responseObject;
        if (isSuccessRsp(jsonRsp))
        {
            [SVProgressHUD showSuccessWithStatus:@"提交成功"];
            [weakSelf popToListVC];
        }
        
    } failure:^(NSString *errorMsg) {
   
        [SVProgressHUD showErrorWithStatus:errorMsg.description];
    }];
}

- (void)popToListVC
{
    //[self.navigationController popViewControllerAnimated:YES];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

//请课时假的接口参数 http://211.65.216.54/uploadAction.do?type=2&leaveType=2&userCode=xiaohu&leaveDate=2016-02-26&courseNumber=1,2,3&termId=1 //考勤的时候type=2 写死2 服务端有用 leaveType请假类型(1按天请假2请课假 3外出假) leaveReason请假理由courseId课程主键leaveDate请假日期weekDay星期几courseNumber第几节课startDate开始日期(yyyy-MM-dd)endDate结束日期(yyyy-MM-dd) termId//学期id

//ASLoginUserInfo* loginInfo = [ASAppDelegate sharedAppDelegate].userInfo;
- (void)uploadImage
{
    NSString* refer = @"uploadAction.do?";
    NSString* prefix = kASHttpUrl(refer);

    NSString* courseUrl = [NSString stringWithFormat:@"%@userCode=%@", prefix,AS_APP_UserCode];
    [SVProgressHUD showWithStatus:@"上传照片..." maskType:SVProgressHUDMaskTypeClear];
    typeof(self) __weak weakSelf = self;
    __block BOOL bUpLoad = NO;
    
    for (unsigned int i = 0; i < _arrImage.count; i++)
    {
        NSData* data = [_arrImage objectAtIndex:i];
        UIImage* image = [UIImage imageWithData:data];
        ASNetworkEngine *networkingEngine = [ASNetworkEngine sharedInstance];
        [networkingEngine uploadImageWithUril:courseUrl image:image progressBlock:^(long long bytesRead, long long totalBytes) {
            
        } completionBlock:^(id responseObject) {
            
            bUpLoad = YES;
            weakSelf.iCount += 1;
            if (weakSelf.arrImage.count == weakSelf.iCount)
            {
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"upload [%d] success",weakSelf.iCount]];
                [SVProgressHUD dismiss];
                
                if (!_bIsOutLeave)
                {
                    [self applyForClass:_strDate courseNumId:_strCourseNum];
                }
                else
                {
                    [self ApplyForOutHoliday:_sSelectDate];
                }
            }
            else
            {
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"upload [%d] success",weakSelf.iCount]];
            }
            
        } failure:^(NSString *errorMsg) {
            
            weakSelf.iCount += 1;
            if (weakSelf.arrImage.count == weakSelf.iCount)
            {
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"upload [%d] fail",weakSelf.iCount]];
                [SVProgressHUD dismiss];
                if (bUpLoad)
                {
                    if (!_bIsOutLeave)
                    {
                        [self applyForClass:_strDate courseNumId:_strCourseNum];
                    }
                    else
                    {
                        [self ApplyForOutHoliday:_sSelectDate];
                    }
                }
            }
            else
            {
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"upload [%d] fail",weakSelf.iCount]];
            }
            NSLog(@"file upload failed %@",errorMsg.description);
        }];
    }
}


//外出假接口 http://211.65.216.54/uploadAction.do?type=2&leaveType=3&userCode=xiaohu&leaveDate=2016-02-26&termId=1 //考勤外出假的时候type=3 写死2 服务端有用 leaveType请假类型(1按天请假2请课假 3外出假) leaveReason请假理由courseId课程主键leaveDate请假日期weekDay星期几courseNumber第几节课startDate开始日期(yyyy-MM-dd)endDate结束日期(yyyy-MM-dd) termId//学期id

- (void)ApplyForOutHoliday:(NSString*)sDate
{
    NSString* refer = @"uploadAction.do?";
    NSString* prefix = kASHttpUrl(refer);
    
    //ASLoginUserInfo* loginInfo = [ASAppDelegate sharedAppDelegate].userInfo;
    
    NSString* courseUrl = [NSString stringWithFormat:@"%@type=%@&leaveType=%@&leaveReason=%@&userCode=%@&leaveDate=%@&termId=%@",prefix, @"2", @"3", _actContentTxtView.text, AS_APP_UserCode, sDate, @"1"];
    
    [SVProgressHUD showWithStatus:@"申请外出假..." maskType:SVProgressHUDMaskTypeClear];
    ASNetworkEngine *networkingEngine = [ASNetworkEngine sharedInstance];
    [networkingEngine GET:courseUrl parameters:nil success:^(id responseObject) {
        NSDictionary* jsonRsp = (NSDictionary *)responseObject;
        jsonRsp = [jsonRsp processDictionaryIsNSNull:jsonRsp];
        if (isSuccessRsp(jsonRsp))
        {
            [SVProgressHUD showErrorWithStatus:errorMsgInfoRsp(jsonRsp)];
            
            [SVProgressHUD dismiss];
            
            [self.navigationController popViewControllerAnimated:YES];
            
        }
        else
        {
            [SVProgressHUD showErrorWithStatus:errorMsgRsp(jsonRsp)];
        }
    } failure:^(NSError *error) {
        //[SVProgressHUD showErrorWithStatus:error.description];
        [SVProgressHUD showErrorWithStatus:@"网络异常，请稍后再试"];
    }];
}

//申请课时假
- (void)applyForClass:(NSString*)sDate courseNumId:(NSString*)courceNumId
{
    NSString* refer = @"uploadAction.do?";
    NSString* prefix = kASHttpUrl(refer);
    
    //ASLoginUserInfo* loginInfo = [ASAppDelegate sharedAppDelegate].userInfo;
    
    NSString* courseUrl = [NSString stringWithFormat:@"%@type=%@&leaveType=%@&leaveReason=%@&userCode=%@&leaveDate=%@&courseNumber=%@&termId=%@",prefix, @"2", @"2", _actContentTxtView.text,AS_APP_UserCode, sDate, courceNumId, @"1"];
    
    [SVProgressHUD showWithStatus:@"申请课时假..." maskType:SVProgressHUDMaskTypeClear];
    ASNetworkEngine *networkingEngine = [ASNetworkEngine sharedInstance];
    [networkingEngine GET:courseUrl parameters:nil success:^(id responseObject) {
        
        NSDictionary* jsonRsp = (NSDictionary *)responseObject;
        jsonRsp = [jsonRsp processDictionaryIsNSNull:jsonRsp];
        if (isSuccessRsp(jsonRsp))
        {
            [SVProgressHUD showErrorWithStatus:errorMsgInfoRsp(jsonRsp)];
            
            [SVProgressHUD dismiss];
            
            [self.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            [SVProgressHUD showErrorWithStatus:errorMsgRsp(jsonRsp)];
        }
    } failure:^(NSError *error) {
        
        //[SVProgressHUD showErrorWithStatus:error.description];
        [SVProgressHUD showErrorWithStatus:@"网络异常，请稍后再试"];
    }];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.row)
    {
       AppForClaLeaUpLoadPhotoCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AppForClaLeaUpLoadPhotoCell class])];
        cell.infoLab.text = @"从相册上传";
        [cell.photoImage setImage:[UIImage imageNamed:@"ic_album"]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    
    static NSString* indentifier = @"tableViewCell";
    UITableViewCell* tabCell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!tabCell)
    {
        tabCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    
    if(nil == _actContentTxtView)
    {
        _actContentTxtView = [[UITextView alloc] initWithFrame:CGRectMake(5,
                                                                          5,
                                                                          [UIScreen mainScreen].bounds.size.width,
                                                                          UpRemarkLoadCellHeight - 10)];
        _actContentTxtView.delegate = self;
        _actContentTxtView.textColor = [UIColor blackColor];
        _actContentTxtView.textAlignment = NSTextAlignmentLeft;
        _actContentTxtView.backgroundColor =  [UIColor clearColor];
        _actContentTxtView.font = [UIFont systemFontOfSize:16.0];
        _actContentTxtView.layer.cornerRadius = 3;
        _actContentTxtView.returnKeyType = UIReturnKeyDone;
        _actContentLab = [[UILabel alloc] initWithFrame:CGRectMake(5, 7, _actContentTxtView.frame.size.width, 20)];
        _actContentLab.enabled = NO;//lable必须设置为不可用
        _actContentLab.backgroundColor = [UIColor clearColor];
        _actContentLab.text = @"申请课时假备注描述";
        _actContentLab.font = [UIFont systemFontOfSize:16.0];
        _actContentLab.textColor = [UIColor colorWithRed:134/255.0 green:139/255.0 blue:142/255.0 alpha:1];
        [_actContentTxtView addSubview:_actContentLab];
        tabCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [tabCell.contentView addSubview:_actContentTxtView];
    }
    
    return tabCell;
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    _tableView.frame = CGRectMake(0, -50, self.view.frame.size.width, self.view.frame.size.height);

    return YES;
}

- (void)textViewDidChange:(UITextView *)textView;
{
    //NSString *content = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
    if (textView.text.length == 0)
    {
        _actContentLab.text = @"申请课时假备注描述";
    }
    else
    {
        _actContentLab.text = @"";
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        _tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        [textView resignFirstResponder];
        
        return YES;
    }
    
    return YES;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (1 == indexPath.row)
    {
        return  UpRemarkLoadCellHeight;
    }
    
    return UpLoadPhotoCellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    [_actContentTxtView resignFirstResponder];
    _tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    if ( 0 == indexPath.row)
    {
        [self addImage];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}


@end




